package com.project.controller;
import com.github.pagehelper.PageInfo;
import com.project.bean.TopicBean;
import com.project.bean.UserBean;
import com.project.service.ITopicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;

@RestController
@RequestMapping("topic")
public class TopicController {
    @Autowired
    private ITopicService service;


    @RequestMapping("findByItem")
    public PageInfo<TopicBean> findByItem(int channelId, int pageNo,String name, String author,
                                          LocalDateTime startDate, LocalDateTime endDate){

        return service.findByItem(channelId, pageNo, name, author, startDate, endDate);
    }

    @RequestMapping("add")
    public void add(TopicBean topic, HttpServletRequest request){
        UserBean user = (UserBean) request.getSession().getAttribute("loginUser");
        topic.getUser().setId(user.getId());
        service.add(topic);
    }

    @RequestMapping("findById")
    public TopicBean findById(int id){
        return  service.findById(id);
    }
}
